package backpage.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

@Data
@TableName("employee")
public class Employee {
    @TableId(value = "employee_id", type = IdType.AUTO)
    private Integer employeeId; // 员工ID

    @TableField(value = "employee_no")
    private String employeeNo; // 员工号

    @TableField(value = "employee_name")
    private String employeeName; // 员工姓名

    @TableField(value = "employee_phone")
    private String employeePhone; // 员工电话

    @TableField(value = "email")
    private String email; // 邮箱

    @TableField(value = "department_id")
    private Integer departmentId; // 部门ID

    @TableField(value = "gender")
    private Integer gender; // 性别：0为男，1为女，2为未知

    @TableField(value = "account")
    private String account; // 账号

    @TableField(value = "password")
    private String password; // 密码

    @TableField(value = "role")
    private Integer role; // 角色：0为普通员工，1为部长，2为总经理

    @TableField(value = "position")
    private String position; // 职位

    @TableField(value = "hire_date")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    private Date hireDate; // 入职日期

    @TableField(value = "birth_date")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    private Date birthDate; // 出生日期

    @TableField(value = "is_active")
    private Boolean isActive; // 是否在职

    @TableField(value = "current_salary_level")
    private Integer currentSalaryLevel; // 现薪资级别

    @TableField(value = "remaining_annual_leave")
    private Integer remainingAnnualLeave; // 剩余年假天数

    @TableField(value = "comments")
    private String comments; // 备注

    // Getter 和 Setter 方法
    public Integer getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(Integer employeeId) {
        this.employeeId = employeeId;
    }

    public String getEmployeeNo() {
        return employeeNo;
    }

    public void setEmployeeNo(String employeeNo) {
        this.employeeNo = employeeNo;
    }

    public String getEmployeeName() {
        return employeeName;
    }

    public void setEmployeeName(String employeeName) {
        this.employeeName = employeeName;
    }

    public String getEmployeePhone() {
        return employeePhone;
    }

    public void setEmployeePhone(String employeePhone) {
        this.employeePhone = employeePhone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(Integer departmentId) {
        this.departmentId = departmentId;
    }

    public Integer getGender() {
        return gender;
    }

    public void setGender(Integer gender) {
        this.gender = gender;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getRole() {
        return role;
    }

    public void setRole(Integer role) {
        this.role = role;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public Date getHireDate() {
        return hireDate;
    }

    public void setHireDate(Date hireDate) {
        this.hireDate = hireDate;
    }

    public Date getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }

    public Boolean getIsActive() {
        return isActive;
    }

    public void setIsActive(Boolean isActive) {
        this.isActive = isActive;
    }

    public Integer getCurrentSalaryLevel() {
        return currentSalaryLevel;
    }

    public void setCurrentSalaryLevel(Integer currentSalaryLevel) {
        this.currentSalaryLevel = currentSalaryLevel;
    }

    public Integer getRemainingAnnualLeave() {
        return remainingAnnualLeave;
    }

    public void setRemainingAnnualLeave(Integer remainingAnnualLeave) {
        this.remainingAnnualLeave = remainingAnnualLeave;
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }
    /**
     * 根据入职时间计算出从入职时间到现在的整年数
     *author 吴文钦
     * @return 整年数
     */
    int getYearsSinceHire() {
        if (this.hireDate == null) {
            return 0;
        }

        LocalDate hireLocalDate = this.hireDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        LocalDate now = LocalDate.now();

        // 计算完整的年数
        int yearsDifference = now.getYear() - hireLocalDate.getYear();

        // 如果当前日期还没到入职日期的月份和日期，则年数减1
        if (now.getMonthValue() < hireLocalDate.getMonthValue() ||
                (now.getMonthValue() == hireLocalDate.getMonthValue() && now.getDayOfMonth() < hireLocalDate.getDayOfMonth())) {
            yearsDifference--;
        }

        return Math.max(0, yearsDifference);
    }
}
